﻿using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;
using MyFloridaHouse.LibDTO;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.DTO;

namespace MyFloridaHouse.DataAccess
{

    public partial class DAL_CensusData
    {

        /// <summary>
        /// [Obsolete] Gets the regions.
        /// </summary>
        /// <param name="iLayer">The i layer.</param>
        /// <returns></returns>
        /// <remarks>[Obsolete] SPROC: usp_moGetRegions</remarks>
        public List<SQLRegionDTO> GetRegions(LayerDTO iLayer)
        {
            List<SQLRegionDTO> itemList = new List<SQLRegionDTO>();

            string storedProcedureName = "usp_moGetRegions";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("iLayerID", iLayer.layerid);
                dataPartIDParm.Direction = ParameterDirection.Input;


                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(SQLRegionDTODataContract.DataContract(rdr));
                    }
                }
            }

            //Database db = Connect();
            //DbCommand dbCommand = db.GetStoredProcCommand("usp_moGetRegions");
            //db.AddInParameter(dbCommand, "iLayerID", DbType.Int32, iLayer.layerid);
            //using (IDataReader rdr = db.ExecuteReader(dbCommand))
            //{
            //    while (rdr.Read())
            //    {
            //        itemList.Add(RegionDTODataContract.DataContract(rdr));


            //    }
            //}

            return itemList;
        }
    }
}
